package com.example.managesystem.mapper;

import com.example.managesystem.entity.User;
import com.example.managesystem.vo.UserItemRelaVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserItemRelaMapper {

    /**
     * 根据用户id查询出所有的项目id item_id
     * @param userid
     * @return
     */
    @Select("select item_id from user_item where userid=#{userid}")
    List<Integer> getItemsByUserId(String userid);

    /**
     * 根据item_id和权限 查询出所有的userid
     * @param itemId
     * @return
     */
    @Select("select userid from user_item where item_id=#{itemId} and role = #{role}")
    String getUseIdByItemidWithRole(@Param("itemId") Integer itemId,@Param("role") Integer role);


    void insertUserItem(@Param("userid") String userid,@Param("itemId") Integer itemId, @Param("role") int i, @Param("work") String work);

    /**
     * 根据项目id查询出所有的userid
     * @param itemId
     * @return
     */
    @Select("select userid from user_item where item_id=#{itemId}")
    List<String> getUseridsByItemId(@Param("itemId") Integer itemId);


    /**
     * 根据项目id和用户id查询出用户的角色
     * @param itemId
     * @param userid
     * @return
     */
    @Select("select work from user_item where item_id=#{itemId} and userid=#{userid}")
    String getWorkByItemidWithUserid(@Param("itemId") Integer itemId, @Param("userid") String userid);

    @Select("select userid from user_item where item_id=#{itemId} and role=#{role}")
    List<String> getUseridsByItemidWithRole(@Param("itemId") Integer itemId, @Param("role") Integer role);

    /**
     * 根据项目id和用户id role删除
     * @param itemId
     * @param userid
     * @param role
     */
    @Delete("delete from user_item where item_id=#{itemId} and userid=#{userid} and role=#{role}")
    void deleteUserItem(@Param("itemId") Integer itemId, @Param("userid") String userid, @Param("role")Integer role);

    /**
     * 根据用户id和角色查询出是否 是教师
     * @param userid
     * @param role
     * @return
     */
    @Select("select count(*) from user_item where userid=#{userid} and role=#{role}")
    Integer queryTeacherExistByUserIdWithRole(@Param("userid")String userid, @Param("role") Integer role);

    /**
     * 根据项目id和角色查询出所有的 老师 用户号
     * @param itemId
     * @param i
     * @return
     */
    @Select("select userid from user_item where item_id=#{itemId} and role=#{role}")
   String getidByItemidWithRole(@Param("itemId")Integer itemId,@Param("role") int i);
}
